﻿using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Attributes.DomainAttributes;
using Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Enums;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Baci.Net.ToolKit.ArcGISProGeoprocessor.Models.Converts
{
    public static class DomainConvert
    {
        public static IDomain Convert(string json)
        {
            IDomain domain = JsonConvert.DeserializeObject<Domain>(json);

            switch (domain.type)
            {
                case DomainEnum.GPString:
                    return JsonConvert.DeserializeObject<GPStringAttribute>(json);
                case DomainEnum.GPBoolean:
                    return JsonConvert.DeserializeObject<GPBooleanAttribute>(json);
                case DomainEnum.GPLinearUnit:
                    return JsonConvert.DeserializeObject<GPLinearUnitAttribute>(json);
                case DomainEnum.GPLong:
                    return JsonConvert.DeserializeObject<GPLongAttribute>(json);
                case DomainEnum.GPTimeUnit:
                    return JsonConvert.DeserializeObject<GPTimeUnitAttribute>(json);
                case DomainEnum.GPDouble:
                    return JsonConvert.DeserializeObject<GPDoubleAttribute>(json);
                case DomainEnum.GPFeatureClassDomain:
                    return JsonConvert.DeserializeObject<GPFeatureClassDomainAttribute>(json);
                case DomainEnum.GPCodedValueDomain:
                    return JsonConvert.DeserializeObject<GPCodedValueDomainAttribute>(json);
                case DomainEnum.GPFileDomain:
                    return JsonConvert.DeserializeObject<GPFileDomainAttribute>(json);
                case DomainEnum.GPNumericDomain:
                    return JsonConvert.DeserializeObject<GPNumericDomainAttribute>(json);
                case DomainEnum.GPCompositeDomain:
                    return JsonConvert.DeserializeObject<GPCompositeDomainAttribute>(json);
                case DomainEnum.GPFieldDomain:
                    return JsonConvert.DeserializeObject<GPFieldDomainAttribute>(json);
                case DomainEnum.GPSceneServiceLayerDomain:
                    return JsonConvert.DeserializeObject<GPSceneServiceLayerDomainAttribute>(json);
                case DomainEnum.GPRangeDomain:
                    return JsonConvert.DeserializeObject<GPRangeDomainAttribute>(json);
                case DomainEnum.GPDatasetDomain:
                    return JsonConvert.DeserializeObject<GPDatasetDomainAttribute>(json);
                case DomainEnum.GPSAGeoDataDomain:
                    return JsonConvert.DeserializeObject<GPSAGeoDataDomainAttribute>(json);
                case DomainEnum.GPSARemapDomain:
                    return JsonConvert.DeserializeObject<GPSARemapDomainAttribute>(json);
                case DomainEnum.GPTablesDomain:
                    return JsonConvert.DeserializeObject<GPTablesDomainAttribute>(json);
                case DomainEnum.GPWorkspaceDomain:
                    return JsonConvert.DeserializeObject<GPWorkspaceDomainAttribute>(json);
                case DomainEnum.GPLayerDomain:
                    return JsonConvert.DeserializeObject<GPLayerDomainAttribute>(json);
                case DomainEnum.GPLayersAndTablesDomain:
                    return JsonConvert.DeserializeObject<GPLayersAndTablesDomainAttribute>(json);
                case DomainEnum.GPBrowseFiltersDomain:
                    return JsonConvert.DeserializeObject<GPBrowseFiltersDomainAttribute>(json);
                case DomainEnum.xmlserialize:
                    break;
                case DomainEnum.GPSceneServiceSubLayerDomain:
                    return JsonConvert.DeserializeObject<GPSceneServiceSubLayerDomainAttribute>(json);
                case DomainEnum.GPMapDomain:
                    return JsonConvert.DeserializeObject<GPMapDomainAttribute>(json);
                case DomainEnum.GPLocatorsDomain:
                    return JsonConvert.DeserializeObject<GPLocatorsDomainAttribute>(json);
                case DomainEnum.GPGASearchNeighborhoodDomain:
                    return JsonConvert.DeserializeObject<GPGASearchNeighborhoodDomainAttribute>(json);
                case DomainEnum.GPSANeighborhoodDomain:
                    return JsonConvert.DeserializeObject<GPSANeighborhoodDomainAttribute>(json);
                default:
                    break;
            }

            return null;
        }
    }

    class Domain : IDomain
    {
        public DomainEnum type { get; set; } = DomainEnum.GPString;
    }
}
